package HuaweiOD;

import java.util.Arrays;
import java.util.Scanner;

public class C卷100分5键键盘 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] commands = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        System.out.println(operate(commands));
    }
    
    public static int operate(int[] commands){
        
        int ans = 0,clipBoard = 0, selection = 0;
        for (int command : commands) {
            switch (command){
                case 1:
                    if (selection != 0){
                        ans -= selection;
                        selection = 0;
                    }
                    ans++;
                    break;
                case 2:
                    clipBoard = selection;
                    break;
                case 3:
                    if (selection != 0){
                        ans -= selection;
                        clipBoard = selection;
                        selection = 0;
                    }
                    break;
                case 4:
                    if (selection != 0){
                        ans -= selection;
                        selection = 0;
                    }
                    ans += clipBoard;
                    break;
                case 5:
                    selection = ans;
                    break;
            }
        }
        
        return ans;
    }
}
